#define  _CRT_SECURE_NO_WARNINGS
class Solution {
    void quickSort(vector<int>& nums, int left, int right, int cnt)
    {
        if (left >= right) return;
        int i = left, cur = left, j = right, key = nums[rand() % (right - left + 1) + left];
        while (cur <= j)
        {
            if (nums[cur] < key) swap(nums[i++], nums[cur++]);
            else if (nums[cur] > key) swap(nums[j--], nums[cur]);
            else cur++;
        }
        int A = i - left, B = j - i + 1, C = right - j;
        if (A > cnt)quickSort(nums, left, i - 1, cnt);
        else if (A + B >= cnt) return;
        else quickSort(nums, j + 1, right, cnt - A - B);
    }
public:
    vector<int> inventoryManagement(vector<int>& stock, int cnt) {
        quickSort(stock, 0, stock.size() - 1, cnt);
        return vector<int>(stock.begin(), stock.begin() + cnt);
    }
};